home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / gpp-1_42.lha / g++-1.42.0 / g++filt.c < prev    next >
C/C++ Source or Header  |  1991-10-19  |  2KB  |  121 lines

  1. /* Demangler filter for GNU C++ 
  2.    Copyright (C) 1989 Free Software Foundation, Inc.
  3.    written by James Clark (jjc@jclark.uucp)
  4.    
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 1, or (at your option)
  8.    any later version.
  9.  
  10.    This program is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <ctype.h>
  22.  
  23. char *malloc ();
  24. char *realloc ();
  25.  
  26. #ifndef __STDC__
  27. #define const
  28. #endif
  29.  
  30. #ifdef __STDC__
  31. extern char *cplus_demangle (const char *);
  32. #else
  33. extern char *cplus_demangle ();
  34. #endif
  35.  
  36. void fatal ();
  37.  
  38. static char *prog_name;
  39.  
  40. #define SYMBOL_MAX 1024
  41.  
  42. #define SYMBOL_CHAR(c) (isascii(c) && (isalnum(c) || (c) == '_' || (c) == '$'))
  43.  
  44. int
  45. main (argc, argv)
  46.      int argc;
  47.      char **argv;
  48. {
  49.   char buf[SYMBOL_MAX+1];
  50.   int c;
  51.  
  52.   prog_name = argv[0];
  53.  
  54.   c = getchar ();
  55.   while (c != EOF)
  56.     {
  57.       int i = 0;
  58.       while (c != EOF && !SYMBOL_CHAR (c))
  59.     {
  60.       putchar (c);
  61.       c = getchar ();
  62.     }
  63.       while (i < SYMBOL_MAX && c != EOF && SYMBOL_CHAR (c))
  64.     {
  65.       buf[i++] = c;
  66.       c = getchar ();
  67.     }
  68.       buf[i] = '\0';
  69.       if (i == SYMBOL_MAX)
  70.     {
  71.       fputs (buf, stdout);
  72.       while (c != EOF && SYMBOL_CHAR (c))
  73.         {
  74.           putchar (c);
  75.           c = getchar ();
  76.         }
  77.     }
  78.       else
  79.     {
  80.       char *result;
  81.       if (i > 0 && (result = cplus_demangle (buf)) != NULL)
  82.         {
  83.           fputs (result, stdout);
  84.           free (result);
  85.         }
  86.       else
  87.         fputs (buf, stdout);
  88.     }
  89.     }
  90.   return 0;
  91. }
  92.  
  93. char *
  94. xmalloc (n)
  95.      int n;
  96. {
  97.   char *tem = malloc (n);
  98.   if (tem == NULL)
  99.     fatal ("out of memory");
  100.   return tem;
  101. }
  102.  
  103. char *
  104. xrealloc (p, n)
  105.      char *p;
  106.      int n;
  107. {
  108.   char *tem = realloc (p, n);
  109.   if (tem == NULL)
  110.     fatal ("out of memory");
  111.   return tem;
  112. }
  113.  
  114. void
  115. fatal (message)
  116.      const char *message;
  117. {
  118.   fprintf (stderr, "%s: %s\n", prog_name, message);
  119.   exit (1);
  120. }
  121.